/*
 * Created by JFormDesigner on Sun Apr 15 15:01:20 CEST 2012
 */

package info.rflow.ui;

import info.rflow.SesManListener;
import info.rflow.SessionManager;
import info.rflow.WorkflowContext;

import java.awt.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


/**
 * @author Holger Brandl
 */
public class StatusBar extends JPanel {

    private SessionManager sesMan;

    private WorkflowContext activeWorkflow;


    public void setSessionManager(SessionManager sesMan) {
        this.sesMan = sesMan;
        sesMan.addSesManListener(new SesManListener() {


            @Override
            public void newActiveScene(WorkflowContext activeWorkflow) {
                StatusBar.this.activeWorkflow = activeWorkflow;
                wdPanel.setWorkflow(activeWorkflow);
            }


            @Override
            public void removedScene(WorkflowContext sc) {
            }


            @Override
            public void addedScene(WorkflowContext sc) {
            }
        });


    }


    public StatusBar() {
        initComponents();


//        zoomSlider.setValue((int) (shelfViewModel.getZoomFactor() * 100));
    }


    private void zoomSliderChanged() {
        int curSliderLevel = zoomSlider.getValue();

        if (curSliderLevel % zoomSlider.getMajorTickSpacing() != 0)
            return;

        final float newZoomFactor = (float) curSliderLevel / 100;
//        if (newZoomFactor != shelfViewModel.getZoomFactor()) {
//            shelfViewModel.setZoomFactor(newZoomFactor);
//        }
    }


    private void zoomSliderChanger() {
        // TODO add your code here
    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        // Generated using JFormDesigner non-commercial license
        statusLabel = new JPanel();
        wdPanel = new WorkingDirectoryPanel();
        label2 = new JLabel();
        label3 = new JLabel();
        label1 = new JLabel();
        zoomSlider = new JSlider();

        //======== this ========
        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

        //======== statusLabel ========
        {
            statusLabel.setLayout(new GridBagLayout());
            ((GridBagLayout) statusLabel.getLayout()).columnWidths = new int[]{0, 0, 0, 0};
            ((GridBagLayout) statusLabel.getLayout()).rowHeights = new int[]{0, 0};
            ((GridBagLayout) statusLabel.getLayout()).columnWeights = new double[]{1.0, 0.0, 1.0, 1.0E-4};
            ((GridBagLayout) statusLabel.getLayout()).rowWeights = new double[]{1.0, 1.0E-4};
            statusLabel.add(wdPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                    new Insets(0, 0, 0, 0), 0, 0));

            //---- label2 ----
            label2.setText("Status: ");
            statusLabel.add(label2, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                    new Insets(0, 0, 0, 0), 0, 0));
            statusLabel.add(label3, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                    new Insets(0, 0, 0, 0), 0, 0));
        }
        add(statusLabel);

        //---- label1 ----
        label1.setText(" Zoom");

        //---- zoomSlider ----
        zoomSlider.setMinimum(25);
        zoomSlider.setMaximum(160);
        zoomSlider.setValue(100);
        zoomSlider.setSnapToTicks(true);
        zoomSlider.setMajorTickSpacing(25);
        zoomSlider.setPreferredSize(new Dimension(99, 29));
        zoomSlider.setMaximumSize(null);
        zoomSlider.setMinimumSize(null);
        zoomSlider.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                zoomSliderChanger();
                zoomSliderChanged();
            }
        });
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }


    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    // Generated using JFormDesigner non-commercial license
    private JPanel statusLabel;
    private WorkingDirectoryPanel wdPanel;
    private JLabel label2;
    private JLabel label3;
    private JLabel label1;
    private JSlider zoomSlider;
    // JFormDesigner - End of variables declaration  //GEN-END:variables


}
